<template>
    <div class="operateBrokerageRule">
        <el-breadcrumb separator="/" class="bread-title">
            <el-breadcrumb-item :to="{ path: '/brokerageRuleList' }">结佣规则</el-breadcrumb-item>
            <el-breadcrumb-item v-if="pageType==='add'">新增</el-breadcrumb-item>
            <el-breadcrumb-item v-if="pageType==='edit'">编辑</el-breadcrumb-item>
        </el-breadcrumb>
        <div class="my-step">
            <el-steps :space="200" :active="active" align-center>
                <el-step title="选择经纪人类型"></el-step>
                <el-step title="选择适用楼盘"></el-step>
                <el-step title="结佣公式"></el-step>
                <el-step title="设置套餐"></el-step>
            </el-steps>
            <div class="cesuan" v-show="active==4" @click="finish(3)">
                <div class="cesuan-img"><img src="./jisuanqi.png" alt="" width="32" height="32"></div>
                <div>佣金测算</div>
            </div>
        </div>
        <el-form ref="form" :model="form" label-width="200px" :rules="rules">
            <!-----------------------------------选择经纪人类型 -------------------------------------------->
            <div v-show="active == 1">
                <h3 style="margin-top: 50px;">请选择 结佣规则 适用的角色类型</h3>
                <hr>
                <el-form-item label="角色：">
                    <el-radio-group v-model="roletype" @change="roleTypeChange">
                        <el-radio :label="3">职业经纪人</el-radio>
                        <el-radio :label="0">网络推客</el-radio>
                        <el-radio :label="-1">自来客</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="next">下一步</el-button>
                </el-form-item>
            </div>
            <!----------------------------------- 第二步 选择适用楼盘 -------------------------------------------->
            <div v-show="active == 2">
                <h3 style="margin-top: 50px;">请选择，适用楼盘的名称</h3>
                <hr>
                <el-form-item label="请选择：">
                    城市：
                    <el-select placeholder="请选择" v-model="curCity" @change="loadDev" filterable>
                        <el-option
                                v-for="item in citys"
                                :key="item.cityId"
                                :label="item.city"
                                :value="item.cityId">
                        </el-option>
                    </el-select>
                    &nbsp;&nbsp;楼盘名称：
                    <el-select placeholder="请选择" v-model="curDev" filterable>
                        <el-option
                                v-for="(item,index) in devs"
                                :key="item.devId + index"
                                :label="item.devName"
                                :value="item.devId">
                        </el-option>
                    </el-select>
                    <el-button type="primary" @click="addDev">添加</el-button>
                </el-form-item>
                <el-form-item label="已选择：">
                    <div v-for="(x,index) in checked" :key="index" class="contact">
                        {{x.name}}
                        <i class="close-icon" @click="deleteDev(index)">×</i>
                    </div>
                </el-form-item>

                <h3 style="margin-top: 50px;">请设置，适用楼盘的结佣规则</h3>
                <hr>
                <el-form-item label="佣金类型：" required>
                    <el-radio-group v-model="form.brokerageType">
                        <el-radio :label="1">前佣</el-radio>
                        <el-radio :label="2">后佣</el-radio>
                        <el-radio :label="3">前佣+后佣</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="套餐有效期：" required>
                    <el-date-picker
                        v-model="form.packageStarTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择开始时间"
                        :picker-options="pickerOption">
                    </el-date-picker>
                    至
                    <el-date-picker
                        v-model="form.packageEndTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择结束时间"
                        :picker-options="pickerOption">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="请选择适合的节点规则：" required>
                    <el-select placeholder="请选择" v-model="form.nodeRuleId" @change="getNodeRuleDetail" filterable>
                        <el-option
                                v-for="item in nodeRulesList"
                                :key="item.id"
                                :label="item.nodeRuleName"
                                :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="prev">上一步</el-button>
                    <el-button type="primary" @click="next">下一步</el-button>
                </el-form-item>
            </div>
            <!----------------------------------- 第三步 结佣公式 -------------------------------------------->
            <div v-show="active == 3">
                <h3 style="margin-top: 50px;">请设置，结佣公式</h3>
                <hr>
                <div v-if="form.brokerageType === 1 || form.brokerageType === 3">
                    <h4 style="margin-top: 50px;">前佣公式</h4>
                    <el-form-item label="快捷公式：">
                        <el-radio-group v-model="form.front.formula" @change="toggleFormula(form.front.formula,'front')">
                            <el-radio :label="1" style="line-height: 40px;">金额</el-radio>
                            <el-radio :label="2">含税成交价*佣金比例&nbsp;&nbsp;&nbsp;</el-radio>
                            <el-radio :label="3">含税成交价*佣金比例 +金额</el-radio>
                            <br>
                            <el-radio :label="6" style="line-height: 40px;">建筑面积</el-radio>
                            <el-radio :label="4">不含税成交价*佣金比例</el-radio>
                            <el-radio :label="5">不含税成交价*佣金比例 +金额</el-radio>
                            <br>
                            <el-radio :label="7" style="line-height: 40px;">套内面积</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item style="padding-left: 82px;" v-show="form.front.formula == 4 || form.front.formula == 5">
                        <div style="float: left; width: 230px;">
                            <el-form-item prop="front.HouseMoneyTaxPoint">
                                *房款税点：
                                <el-input v-model="form.front.HouseMoneyTaxPoint" style="width: 120px;"></el-input>
                            </el-form-item>
                        </div>
                        <div style="float: left; width: 340px;">
                            <el-form-item prop="date" label="">
                                *装修款（或其他款项）税点：
                                <el-input v-model="form.front.RenovationTaxPoint" style="width: 120px;"></el-input>
                            </el-form-item>
                        </div>
                    </el-form-item>
                </div>
                <div v-if="form.brokerageType === 2 || form.brokerageType === 3">
                    <h4 style="margin-top: 50px;">后佣公式</h4>
                    <el-form-item label="快捷公式：">
                        <el-radio-group v-model="form.end.formula" @change="toggleFormula(form.end.formula,'end')">
                            <el-radio :label="1" style="line-height: 40px;">金额</el-radio>
                            <el-radio :label="2">含税成交价*佣金比例&nbsp;&nbsp;&nbsp;</el-radio>
                            <el-radio :label="3">含税成交价*佣金比例 +金额</el-radio>
                            <br>
                            <el-radio :label="6" style="line-height: 40px;">建筑面积</el-radio>
                            <el-radio :label="4">不含税成交价*佣金比例</el-radio>
                            <el-radio :label="5">不含税成交价*佣金比例 +金额</el-radio>
                            <br>
                            <el-radio :label="7" style="line-height: 40px;">套内面积</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item style="padding-left: 82px;" v-show="form.end.formula == 4 || form.end.formula == 5">
                        <div style="float: left; width: 230px;">
                            <el-form-item prop="date2">
                                *房款税点：
                                <el-input v-model="form.end.HouseMoneyTaxPoint" style="width: 120px;"></el-input>
                            </el-form-item>
                        </div>
                        <div style="float: left; width: 340px;">
                            <el-form-item prop="date" label="">
                                *装修款（或其他款项）税点：
                                <el-input v-model="form.end.RenovationTaxPoint" style="width: 120px;"></el-input>
                            </el-form-item>
                        </div>
                    </el-form-item>
                </div>
                <div v-if="form.isAward === 1 && roletype==3">
                    <h4 style="margin-top: 50px;">经纪人奖励公式</h4>
                    <el-form-item label="快捷公式：">
                        <el-radio-group v-model="form.bro.formula">
                            <el-radio :label="1">金额</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </div>
                <div class="tips">
                    <div>含税成交价=房款总价+装修款（或其他款项）；</div>
                    <div>不含税成交价=房款总价/（1+5%）+（成交价-房款总价）/（1+11%）；</div>
                    <div>5%、11%两个税点可自行设置</div>
                </div>

                <el-form-item>
                    <el-button type="primary" @click="prev">上一步</el-button>
                    <el-button type="primary" @click="next">下一步</el-button>
                </el-form-item>
            </div>
            <!----------------------------------- 第四步 设置套餐 -------------------------------------------->
            <div v-show="active == 4">
                <h3 style="margin-top: 50px;">请设置佣金套餐</h3>
                <hr>
                <table>
                    <tbody v-for="(x,index) in form.formulaPackage" :key="index">
                        <tr>
                            <td rowspan="4" class="title">套餐{{alpha[index]}}</td>
                            <td class="content" v-if="form.brokerageType == 1 || form.brokerageType == 3">
                                <p>前佣</p>
                                <p v-if="form.front.formula == 1" class="clearthis">
                                    <el-form-item label="好生活总收入：" :prop="`formulaPackage.` + index + `.front.goodLifePackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.goodLifePackageAmount" style="width: 120px;"></el-input>
                                        元/套&nbsp;&nbsp;*&nbsp;
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifePercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.goodLifePercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <p v-if="form.front.formula == 2" class="clearthis">
                                    <el-form-item label="好生活总收入："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.front.goodLifeProportion`" style="float: left;">
                                        含税成交价 * <el-input v-model="x.front.goodLifeProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifePercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.front.goodLifePercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <div v-if="form.front.formula == 3" class="clear">
                                    <el-form-item label="好生活总收入：" style="float: left"
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.front.goodLifeProportion`">
                                        【含税成交价*<el-input v-model="x.front.goodLifeProportion" style="width: 120px;"></el-input>
                                        %/套+
                                    </el-form-item>
                                    <el-form-item label="金额" style="float: left"
                                                  :rules="rules.brokerageAmount"
                                                  :prop="`formulaPackage.` + index + `.front.goodLifeAmount`">
                                        <el-input v-model="x.front.goodLifeAmount" style="width: 120px;"></el-input>
                                        元/套】
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifePercentage`"
                                                  :rules="rules.packageAmountPercent" style="float: left;">
                                        <el-input v-model="x.front.goodLifePercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                                <p v-if="form.front.formula == 4" class="clearthis">
                                    <el-form-item label="好生活总收入："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.front.goodLifeProportion`" style="float: left;">
                                        不含税成交价 * <el-input v-model="x.front.goodLifeProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifePercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.front.goodLifePercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <div v-if="form.front.formula == 5" class="clear">
                                    <div>
                                        <el-form-item label="好生活总收入：" style="float: left"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.front.goodLifeProportion`">
                                            【不含税成交价*<el-input v-model="x.front.goodLifeProportion" style="width: 120px;"></el-input>
                                            %/套+
                                        </el-form-item>
                                        <el-form-item label="金额" style="float: left"
                                                      :rules="rules.brokerageAmount"
                                                      :prop="`formulaPackage.` + index + `.front.goodLifeAmount`">
                                            <el-input v-model="x.front.goodLifeAmount" style="width: 120px;"></el-input>
                                            元/套】
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifePercentage`"
                                                      :rules="rules.packageAmountPercent" style="float: left;">
                                            <el-input v-model="x.front.goodLifePercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                </div>
                                <p v-if="form.front.formula == 6||form.front.formula == 7" class="clearthis">
                                    <el-form-item label="好生活总收入：" :prop="`formulaPackage.` + index + `.front.goodLifePackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.goodLifePackageAmount" style="width: 120px;"></el-input>
                                        元/平米&nbsp;&nbsp;*&nbsp;
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifePercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.goodLifePercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <!--业绩确认节点-->
                                <p>
                                    <el-form-item label="业绩确认节点：" :rules="rules.goodLifeNode" :prop="`formulaPackage.` + index + `.front.goodLifeNode`" class="commonclass" required>
                                        <el-radio-group v-model="x.front.goodLifeNode" @change="frontChange(x)">
                                            <el-radio :label="item.value" v-for="item in x.customeNode" :key="item.value">{{item.label}}</el-radio>
                                        </el-radio-group>
                                    </el-form-item>
                                </p>

                                <!--经纪人分佣-->
                                <div v-if="roletype!=-1">
                                    <hr>
                                    <div v-if="form.front.formula == 1" class="clearthis">
                                        <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'" :prop="`formulaPackage.` + index + `.front.packageAmount`"
                                                      :rules="rules.packageAmount" style="float: left;">
                                            <el-input v-model="x.front.packageAmount" style="width: 120px;"></el-input>
                                            元/套   *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.brokeragePercentage`"
                                                      :rules="rules.packageAmount" style="float: left;">
                                            <el-input v-model="x.front.brokeragePercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                    <div v-if="form.front.formula == 2" class="clearthis">
                                        <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.front.brokerageProportion`" style="float: left;">
                                            含税成交价 * <el-input v-model="x.front.brokerageProportion" style="width: 120px;"></el-input>
                                            %/套
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.brokeragePercentage`"
                                                      :rules="rules.brokerageProportion" style="float: left;">
                                            <el-input v-model="x.front.brokeragePercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                    <div v-if="form.front.formula == 3" class="clear">
                                        <div>
                                            <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'"
                                                          style="float: left"
                                                          :rules="rules.brokerageProportion"
                                                          :prop="`formulaPackage.` + index + `.front.brokerageProportion`">
                                                【含税成交价*<el-input v-model="x.front.brokerageProportion" style="width: 120px;"></el-input>
                                                %/套+
                                            </el-form-item>
                                            <el-form-item label="金额" style="float: left"
                                                          :rules="rules.brokerageAmount"
                                                          :prop="`formulaPackage.` + index + `.front.brokerageAmount`">
                                                <el-input v-model="x.front.brokerageAmount" style="width: 120px;"></el-input>
                                                元/套】
                                                *
                                            </el-form-item>
                                            <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.brokeragePercentage`"
                                                          :rules="rules.packageAmountPercent" style="float: left;">
                                                <el-input v-model="x.front.brokeragePercentage" style="width: 120px;"></el-input> %
                                            </el-form-item>
                                        </div>
                                    </div>
                                    <p v-if="form.front.formula == 4" class="clearthis">
                                        <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.front.brokerageProportion`" style="float: left;">
                                            不含税成交价 * <el-input v-model="x.front.brokerageProportion" style="width: 120px;"></el-input>
                                            %/套
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.brokeragePercentage`"
                                                      :rules="rules.brokerageProportion" style="float: left;">
                                            <el-input v-model="x.front.brokeragePercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </p>
                                    <div v-if="form.front.formula == 5" class="clear">
                                        <div>
                                            <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'"
                                                          style="float: left"
                                                          :rules="rules.brokerageProportion"
                                                          :prop="`formulaPackage.` + index + `.front.brokerageProportion`">
                                                【不含税成交价*<el-input v-model="x.front.brokerageProportion" style="width: 120px;"></el-input>
                                                %/套+
                                            </el-form-item>
                                            <el-form-item label="金额" style="float: left"
                                                          :rules="rules.brokerageAmount"
                                                          :prop="`formulaPackage.` + index + `.front.brokerageAmount`">
                                                <el-input v-model="x.front.brokerageAmount" style="width: 120px;"></el-input>
                                                元/套】
                                                *
                                            </el-form-item>
                                            <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.brokeragePercentage`"
                                                          :rules="rules.packageAmountPercent" style="float: left;">
                                                <el-input v-model="x.front.brokeragePercentage" style="width: 120px;"></el-input> %
                                            </el-form-item>
                                        </div>
                                    </div>
                                    <div v-if="form.front.formula == 6||form.front.formula == 7" class="clearthis">
                                        <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'" :prop="`formulaPackage.` + index + `.front.packageAmount`"
                                                      :rules="rules.packageAmount" style="float: left;">
                                            <el-input v-model="x.front.packageAmount" style="width: 120px;"></el-input>
                                            元/平米   *&nbsp;
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.brokeragePercentage`"
                                                      :rules="rules.packageAmount" style="float: left;">
                                            <el-input v-model="x.front.brokeragePercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>

                                    <!--节点-->
                                    <div class="clear clearthat commonclass" v-for="(item,index1) in x.front.brokerageNodes" :key="index1">
                                        <el-form-item :label="'节点'+(index1+1)+'：'" style="float: left" v-if="item.nodeName != '回款'">
                                            {{item.nodeName}}
                                            <el-select v-model="item.brokeNodeType" placeholder="请选择" style="width: 120px;">
                                                <el-option
                                                        v-for="item1 in options"
                                                        :key="item1.value"
                                                        :label="item1.label"
                                                        :value="item1.value">
                                                </el-option>
                                            </el-select>
                                            <el-input v-model="item.brokeNodeAmount" style="width: 120px;" @blur="AmountBlur(item.brokeNodeAmount)"></el-input><em>{{item.brokeNodeType == 1 ? '%' : '元'}}</em>
                                        </el-form-item>
                                        <el-form-item style="float: left"  v-if="item.nodeName == '认购'">
                                            <el-checkbox label="上限"
                                                         :true-label="1"
                                                         :false-label="2"
                                                         v-model="x.front.packageUpperLimit" @change="clear(x.front.packageUpperLimit,index,'front')"></el-checkbox>
                                            <el-input :disabled="x.front.packageUpperLimit == 2" v-model="item.upperLimitAmount" style="width: 120px;"></el-input> 元
                                            <span class="pad grey">如果达到结佣上限，认购剩余部分佣金在下个结佣节点发放</span>
                                        </el-form-item>
                                    </div>
                                </div>
                                <hr>
                                <!--好生活分佣-->
                                <div v-if="form.front.formula == 1" class="clearthis">
                                    <el-form-item label="好生活分佣：" :prop="`formulaPackage.` + index + `.front.goodLifeGrantPackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.goodLifeGrantPackageAmount" style="width: 120px;"></el-input>
                                        元/套   *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifeGrantPercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                                <div v-if="form.front.formula == 2" class="clearthis">
                                    <el-form-item label="好生活分佣："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.front.goodLifeGrantProportion`" style="float: left;">
                                        含税成交价 * <el-input v-model="x.front.goodLifeGrantProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifeGrantPercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.front.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                                <div v-if="form.front.formula == 3" class="clear">
                                    <div>
                                        <el-form-item label="好生活分佣：" style="float: left"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.front.goodLifeGrantProportion`">
                                            【含税成交价*<el-input v-model="x.front.goodLifeGrantProportion" style="width: 120px;"></el-input>
                                            %/套+
                                        </el-form-item>
                                        <el-form-item label="金额" style="float: left"
                                                      :rules="rules.brokerageAmount"
                                                      :prop="`formulaPackage.` + index + `.front.goodLifeGrantAmount`">
                                            <el-input v-model="x.front.goodLifeGrantAmount" style="width: 120px;"></el-input>
                                            元/套】
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifeGrantPercentage`"
                                                      :rules="rules.packageAmountPercent" style="float: left;">
                                            <el-input v-model="x.front.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                </div>
                                <p v-if="form.front.formula == 4" class="clearthis">
                                    <el-form-item label="好生活分佣："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.front.goodLifeGrantProportion`" style="float: left;">
                                        不含税成交价 * <el-input v-model="x.front.goodLifeGrantProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifeGrantPercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.front.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <div v-if="form.front.formula == 5" class="clear">
                                    <div>
                                        <el-form-item label="好生活分佣：" style="float: left"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.front.goodLifeGrantProportion`">
                                            【不含税成交价*<el-input v-model="x.front.goodLifeGrantProportion" style="width: 120px;"></el-input>
                                            %/套+
                                        </el-form-item>
                                        <el-form-item label="金额" style="float: left"
                                                      :rules="rules.brokerageAmount"
                                                      :prop="`formulaPackage.` + index + `.front.goodLifeGrantAmount`">
                                            <el-input v-model="x.front.goodLifeGrantAmount" style="width: 120px;"></el-input>
                                            元/套】
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifeGrantPercentage`"
                                                      :rules="rules.packageAmountPercent" style="float: left;">
                                            <el-input v-model="x.front.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                </div>
                                <div v-if="form.front.formula == 6||form.front.formula == 7" class="clearthis">
                                    <el-form-item label="好生活分佣：" :prop="`formulaPackage.` + index + `.front.goodLifeGrantPackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.goodLifeGrantPackageAmount" style="width: 120px;"></el-input>
                                        元/平米   *&nbsp;
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.goodLifeGrantPercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                                <hr>
                                <!--开发商分佣-->
                                <div v-if="form.front.formula == 1" class="clearthis">
                                    <el-form-item label="开发商分佣：" :prop="`formulaPackage.` + index + `.front.openBusinessGrantPackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.openBusinessGrantPackageAmount"
                                                  style="width: 120px;"></el-input>
                                        元/套   *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.openBusinessGrantPercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.openBusinessGrantPercentage"
                                                  style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                                <div v-if="form.front.formula == 2" class="clearthis">
                                    <el-form-item label="开发商分佣："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.front.openBusinessGrantProportion`" style="float: left;">
                                        含税成交价 * <el-input v-model="x.front.openBusinessGrantProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.openBusinessGrantPercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.front.openBusinessGrantPercentage"
                                                  style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                                <div v-if="form.front.formula == 3" class="clear">
                                    <div>
                                        <el-form-item label="开发商分佣：" style="float: left"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.front.openBusinessGrantProportion`">
                                            【含税成交价*<el-input v-model="x.front.openBusinessGrantProportion" style="width: 120px;"></el-input>
                                            %/套+
                                        </el-form-item>
                                        <el-form-item label="金额" style="float: left"
                                                      :rules="rules.brokerageAmount"
                                                      :prop="`formulaPackage.` + index + `.front.openBusinessGrantAmount`">
                                            <el-input v-model="x.front.openBusinessGrantAmount" style="width: 120px;"></el-input>
                                            元/套】
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.openBusinessGrantPercentage`"
                                                      :rules="rules.packageAmountPercent" style="float: left;">
                                            <el-input v-model="x.front.openBusinessGrantPercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                </div>
                                <p v-if="form.front.formula == 4" class="clearthis">
                                    <el-form-item label="开发商分佣："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.front.openBusinessGrantProportion`" style="float: left;">
                                        不含税成交价 * <el-input v-model="x.front.openBusinessGrantProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.openBusinessGrantPercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.front.openBusinessGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <div v-if="form.front.formula == 5" class="clear">
                                    <div>
                                        <el-form-item label="开发商分佣：" style="float: left"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.front.openBusinessGrantProportion`">
                                            【不含税成交价*<el-input v-model="x.front.openBusinessGrantProportion" style="width: 120px;"></el-input>
                                            %/套+
                                        </el-form-item>
                                        <el-form-item label="金额" style="float: left"
                                                      :rules="rules.brokerageAmount"
                                                      :prop="`formulaPackage.` + index + `.front.openBusinessGrantAmount`">
                                            <el-input v-model="x.front.openBusinessGrantAmount" style="width: 120px;"></el-input>
                                            元/套】
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.openBusinessGrantPercentage`"
                                                      :rules="rules.packageAmountPercent" style="float: left;">
                                            <el-input v-model="x.front.openBusinessGrantPercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                </div>
                                <div v-if="form.front.formula == 6||form.front.formula == 7" class="clearthis">
                                    <el-form-item label="开发商分佣：" :prop="`formulaPackage.` + index + `.front.openBusinessGrantPackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.openBusinessGrantPackageAmount"
                                                  style="width: 120px;"></el-input>
                                        元/平米   *&nbsp;
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.front.openBusinessGrantPercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.front.openBusinessGrantPercentage"
                                                  style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                            </td>
                            <td rowspan="4" class="title">
                                <el-button type="primary" @click="delPackage(index)" v-if="index > 0">删除</el-button>
                            </td>
                        </tr>
                        <tr>
                            <td class="content" v-if="form.brokerageType == 2 || form.brokerageType == 3">
                                <p>后佣</p>
                                <p v-if="form.end.formula == 1" class="clearthis">
                                    <el-form-item label="好生活总收入：" :prop="`formulaPackage.` + index + `.end.goodLifePackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.goodLifePackageAmount" style="width: 120px;"></el-input>
                                        元/套 *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifePercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.goodLifePercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <p v-if="form.end.formula == 2" class="clearthis">
                                    <el-form-item label="好生活总收入："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.end.goodLifeProportion`" style="float: left;">
                                        含税成交价*<el-input v-model="x.end.goodLifeProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifePercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.end.goodLifePercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <div v-if="form.end.formula == 3" class="clear">
                                    <el-form-item label="好生活总收入：" style="float: left"
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.end.goodLifeProportion`">
                                        【含税成交价*<el-input v-model="x.end.goodLifeProportion"  style="width: 120px;"></el-input>
                                        %/套+
                                    </el-form-item>
                                    <el-form-item label="金额" style="float: left"
                                                  :rules="rules.brokerageAmount"
                                                  :prop="`formulaPackage.` + index + `.end.goodLifeAmount`">
                                        <el-input v-model="x.end.goodLifeAmount" style="width: 120px;"></el-input>
                                        元/套】
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifePercentage`"
                                                  :rules="rules.packageAmountPercent" style="float: left;">
                                        <el-input v-model="x.end.goodLifePercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                                <p v-if="form.end.formula == 4" class="clearthis">
                                    <el-form-item label="好生活总收入："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.end.goodLifeProportion`" style="float: left;">
                                        不含税成交价 * <el-input v-model="x.end.goodLifeProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifePercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.end.goodLifePercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <div v-if="form.end.formula == 5" class="clear">
                                    <div>
                                        <el-form-item label="好生活总收入：" style="float: left"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.end.goodLifeProportion`">
                                            【不含税成交价*<el-input v-model="x.end.goodLifeProportion" style="width: 120px;"></el-input>
                                            %/套+
                                        </el-form-item>
                                        <el-form-item label="金额" style="float: left"
                                                      :rules="rules.brokerageAmount"
                                                      :prop="`formulaPackage.` + index + `.end.goodLifeAmount`">
                                            <el-input v-model="x.end.goodLifeAmount" style="width: 120px;"></el-input>
                                            元/套】
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifePercentage`"
                                                      :rules="rules.packageAmountPercent" style="float: left;">
                                            <el-input v-model="x.end.goodLifePercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                </div>
                                <p v-if="form.end.formula == 6||form.end.formula == 7" class="clearthis">
                                    <el-form-item label="好生活总收入：" :prop="`formulaPackage.` + index + `.end.goodLifePackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.goodLifePackageAmount" style="width: 120px;"></el-input>
                                        元/平米 *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifePercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.goodLifePercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <!--业绩确认节点-->
                                <p>
                                    <el-form-item label="业绩确认节点：" :rules="rules.goodLifeNode" :prop="`formulaPackage.` + index + `.end.goodLifeNode`">
                                        <el-radio-group v-model="x.end.goodLifeNode" @change="endChange(x)">
                                            <el-radio :label="item.value" :key="item.value" v-for="item in x.customeNode">{{item.label}}</el-radio>
                                        </el-radio-group>
                                    </el-form-item>
                                </p>

                                <!--经纪人分佣-->
                                <div v-if="roletype!=-1">
                                    <hr>
                                    <div v-if="form.end.formula == 1" class="clearthis">
                                        <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'" :prop="`formulaPackage.` + index + `.end.packageAmount`"
                                                      :rules="rules.packageAmount" style="float: left;">
                                            <el-input v-model="x.end.packageAmount" style="width: 120px;"></el-input>
                                            元/套   *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.brokeragePercentage`"
                                                      :rules="rules.packageAmount" style="float: left;">
                                            <el-input v-model="x.end.brokeragePercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                    <p v-if="form.end.formula == 2" class="clearthis">
                                        <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.end.brokerageProportion`" style="float: left;">
                                            含税成交价*<el-input v-model="x.end.brokerageProportion" style="width: 120px;"></el-input>
                                            %/套
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.brokeragePercentage`"
                                                      :rules="rules.brokerageProportion" style="float: left;">
                                            <el-input v-model="x.end.brokeragePercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </p>
                                    <div v-if="form.end.formula == 3" class="clear">
                                        <div>
                                            <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'" style="float: left"
                                                          :rules="rules.brokerageProportion"
                                                          :prop="`formulaPackage.` + index + `.end.brokerageProportion`">
                                                【含税成交价*<el-input v-model="x.end.brokerageProportion" style="width: 120px;"></el-input>
                                                %/套+
                                            </el-form-item>
                                            <el-form-item label="金额" style="float: left"
                                                          :rules="rules.brokerageAmount"
                                                          :prop="`formulaPackage.` + index + `.end.brokerageAmount`">
                                                <el-input v-model="x.end.brokerageAmount" style="width: 120px;"></el-input>
                                                元/套】
                                                *
                                            </el-form-item>
                                            <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.brokeragePercentage`"
                                                          :rules="rules.packageAmountPercent" style="float: left;">
                                                <el-input v-model="x.end.brokeragePercentage" style="width: 120px;"></el-input> %
                                            </el-form-item>
                                        </div>
                                    </div>
                                    <p v-if="form.end.formula == 4" class="clearthis">
                                        <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.end.brokerageProportion`" style="float: left;">
                                            不含税成交价 * <el-input v-model="x.end.brokerageProportion" style="width: 120px;"></el-input>
                                            %/套
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.brokeragePercentage`"
                                                      :rules="rules.brokerageProportion" style="float: left;">
                                            <el-input v-model="x.end.brokeragePercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </p>
                                    <div v-if="form.end.formula == 5" class="clear">
                                        <div>
                                            <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'" style="float: left"
                                                          :rules="rules.brokerageProportion"
                                                          :prop="`formulaPackage.` + index + `.end.brokerageProportion`">
                                                【不含税成交价*<el-input v-model="x.end.brokerageProportion" style="width: 120px;"></el-input>
                                                %/套+
                                            </el-form-item>
                                            <el-form-item label="金额" style="float: left"
                                                          :rules="rules.brokerageAmount"
                                                          :prop="`formulaPackage.` + index + `.end.brokerageAmount`">
                                                <el-input v-model="x.end.brokerageAmount" style="width: 120px;"></el-input>
                                                元/套】
                                                *
                                            </el-form-item>
                                            <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.brokeragePercentage`"
                                                          :rules="rules.packageAmountPercent" style="float: left;">
                                                <el-input v-model="x.end.brokeragePercentage" style="width: 120px;"></el-input> %
                                            </el-form-item>
                                        </div>
                                    </div>
                                    <div v-if="form.end.formula == 6||form.end.formula == 7" class="clearthis">
                                        <el-form-item :label="form.roleList[0] == 3?'经纪人分佣：':'网络推客分佣：'" :prop="`formulaPackage.` + index + `.end.packageAmount`"
                                                      :rules="rules.packageAmount" style="float: left;">
                                            <el-input v-model="x.end.packageAmount" style="width: 120px;"></el-input>
                                            元/平米   *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.brokeragePercentage`"
                                                      :rules="rules.packageAmount" style="float: left;">
                                            <el-input v-model="x.end.brokeragePercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>

                                    <!--节点-->
                                    <div class="clear clearthat commonclass" v-for="(item,index1) in x.end.brokerageNodes" :key="index1">
                                        <el-form-item :label="'节点'+(index1+1)+'：'"  style="float: left">
                                            {{item.nodeName}}
                                            <el-select v-model="item.brokeNodeType" placeholder="请选择" style="width: 120px;" v-if="item.nodeName != '回款'">
                                                <el-option
                                                        v-for="item1 in options"
                                                        :key="item1.value"
                                                        :label="item1.label"
                                                        :value="item1.value">
                                                </el-option>
                                            </el-select>
                                            <el-input v-model="item.brokeNodeAmount" style="width: 120px;" @blur="AmountBlur(item.brokeNodeAmount)" v-if="item.nodeName != '回款'"></el-input><em v-if="item.nodeName != '回款'">{{item.brokeNodeType == 1 ? '%' : '元'}}</em>
                                        </el-form-item>
                                        <el-form-item style="float: left" v-if="item.nodeName == '认购'">
                                            <el-checkbox label="上限"
                                                         :true-label="1"
                                                         :false-label="2"
                                                         v-model="x.end.packageUpperLimit" @change="clear(x.end.packageUpperLimit,index,'end')"></el-checkbox>
                                            <el-input :disabled="x.end.packageUpperLimit == 2" v-model="item.upperLimitAmount" style="width: 120px;"></el-input> 元

                                            <span class="pad grey">如果达到结佣上限，认购剩余部分佣金在下个结佣节点发放</span>
                                        </el-form-item>
                                    </div>
                                </div>
                                <hr>
                                <!--好生活分佣-->
                                <div v-if="form.end.formula == 1" class="clearthis">
                                    <el-form-item label="好生活分佣：" :prop="`formulaPackage.` + index + `.end.goodLifeGrantPackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.goodLifeGrantPackageAmount"
                                                  style="width: 120px;"></el-input>
                                        元/套   *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifeGrantPercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                                <p v-if="form.end.formula == 2" class="clearthis">
                                    <el-form-item label="好生活分佣："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.end.goodLifeGrantProportion`" style="float: left;">
                                        含税成交价*<el-input v-model="x.end.goodLifeGrantProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifeGrantPercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.end.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <div v-if="form.end.formula == 3" class="clear">
                                    <div>
                                        <el-form-item label="好生活分佣：" style="float: left"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.end.goodLifeGrantProportion`">
                                            【含税成交价*<el-input v-model="x.end.goodLifeGrantProportion" style="width: 120px;"></el-input>
                                            %/套+
                                        </el-form-item>
                                        <el-form-item label="金额" style="float: left"
                                                      :rules="rules.brokerageAmount"
                                                      :prop="`formulaPackage.` + index + `.end.goodLifeGrantAmount`">
                                            <el-input v-model="x.end.goodLifeGrantAmount" style="width: 120px;"></el-input>
                                            元/套】
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifeGrantPercentage`"
                                                      :rules="rules.packageAmountPercent" style="float: left;">
                                            <el-input v-model="x.end.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                </div>
                                <p v-if="form.end.formula == 4" class="clearthis">
                                    <el-form-item label="好生活分佣："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.end.goodLifeGrantProportion`" style="float: left;">
                                        不含税成交价 * <el-input v-model="x.end.goodLifeGrantProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifeGrantPercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.end.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <div v-if="form.end.formula == 5" class="clear">
                                    <div>
                                        <el-form-item label="好生活分佣：" style="float: left"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.end.goodLifeGrantProportion`">
                                            【不含税成交价*<el-input v-model="x.end.goodLifeGrantProportion" style="width: 120px;"></el-input>
                                            %/套+
                                        </el-form-item>
                                        <el-form-item label="金额" style="float: left"
                                                      :rules="rules.brokerageAmount"
                                                      :prop="`formulaPackage.` + index + `.end.goodLifeGrantAmount`">
                                            <el-input v-model="x.end.goodLifeGrantAmount" style="width: 120px;"></el-input>
                                            元/套】
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifeGrantPercentage`"
                                                      :rules="rules.packageAmountPercent" style="float: left;">
                                            <el-input v-model="x.end.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                </div>
                                <div v-if="form.end.formula == 6||form.end.formula == 7" class="clearthis">
                                    <el-form-item label="好生活分佣：" :prop="`formulaPackage.` + index + `.end.goodLifeGrantPackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.goodLifeGrantPackageAmount"
                                                  style="width: 120px;"></el-input>
                                        元/平米   *&nbsp;
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.goodLifeGrantPercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.goodLifeGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                                <hr>
                                <!--开发商分佣-->
                                <div v-if="form.end.formula == 1" class="clearthis">
                                    <el-form-item label="开发商分佣：" :prop="`formulaPackage.` + index + `.end.openBusinessGrantPackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.openBusinessGrantPackageAmount" style="width: 120px;"></el-input>
                                        元/套   *&nbsp;
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.openBusinessGrantPercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.openBusinessGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                                <p v-if="form.end.formula == 2" class="clearthis">
                                    <el-form-item label="开发商分佣："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.end.openBusinessGrantProportion`" style="float: left;">
                                        含税成交价*<el-input v-model="x.end.openBusinessGrantProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.openBusinessGrantPercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.end.openBusinessGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <div v-if="form.end.formula == 3" class="clear">
                                    <div>
                                        <el-form-item label="开发商分佣：" style="float: left"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.end.openBusinessGrantProportion`">
                                            【含税成交价*<el-input v-model="x.end.openBusinessGrantProportion" style="width: 120px;"></el-input>
                                            %/套+
                                        </el-form-item>
                                        <el-form-item label="金额" style="float: left"
                                                      :rules="rules.brokerageAmount"
                                                      :prop="`formulaPackage.` + index + `.end.openBusinessGrantAmount`">
                                            <el-input v-model="x.end.openBusinessGrantAmount" style="width: 120px;"></el-input>
                                            元/套】
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.openBusinessGrantPercentage`"
                                                      :rules="rules.packageAmountPercent" style="float: left;">
                                            <el-input v-model="x.end.openBusinessGrantPercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                </div>
                                <p v-if="form.end.formula == 4" class="clearthis">
                                    <el-form-item label="开发商分佣："
                                                  :rules="rules.brokerageProportion"
                                                  :prop="`formulaPackage.` + index + `.end.openBusinessGrantProportion`" style="float: left;">
                                        不含税成交价 * <el-input v-model="x.end.openBusinessGrantProportion" style="width: 120px;"></el-input>
                                        %/套
                                        *
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.openBusinessGrantPercentage`"
                                                  :rules="rules.brokerageProportion" style="float: left;">
                                        <el-input v-model="x.end.openBusinessGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </p>
                                <div v-if="form.end.formula == 5" class="clear">
                                    <div>
                                        <el-form-item label="开发商分佣：" style="float: left"
                                                      :rules="rules.brokerageProportion"
                                                      :prop="`formulaPackage.` + index + `.end.openBusinessGrantProportion`">
                                            【不含税成交价*<el-input v-model="x.end.openBusinessGrantProportion" style="width: 120px;"></el-input>
                                            %/套+
                                        </el-form-item>
                                        <el-form-item label="金额" style="float: left"
                                                      :rules="rules.brokerageAmount"
                                                      :prop="`formulaPackage.` + index + `.end.openBusinessGrantAmount`">
                                            <el-input v-model="x.end.openBusinessGrantAmount" style="width: 120px;"></el-input>
                                            元/套】
                                            *
                                        </el-form-item>
                                        <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.openBusinessGrantPercentage`"
                                                      :rules="rules.packageAmountPercent" style="float: left;">
                                            <el-input v-model="x.end.openBusinessGrantPercentage" style="width: 120px;"></el-input> %
                                        </el-form-item>
                                    </div>
                                </div>
                                <div v-if="form.end.formula == 6||form.end.formula == 7" class="clearthis">
                                    <el-form-item label="开发商分佣：" :prop="`formulaPackage.` + index + `.end.openBusinessGrantPackageAmount`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.openBusinessGrantPackageAmount" style="width: 120px;"></el-input>
                                        元/平米   *&nbsp;
                                    </el-form-item>
                                    <el-form-item label="" label-width="0" :prop="`formulaPackage.` + index + `.end.openBusinessGrantPercentage`"
                                                  :rules="rules.packageAmount" style="float: left;">
                                        <el-input v-model="x.end.openBusinessGrantPercentage" style="width: 120px;"></el-input> %
                                    </el-form-item>
                                </div>
                            </td>
                        </tr>

                        <!--经纪人奖励-->
                        <tr v-if="roletype==3&&form.isAward==1">
                            <td class="content">
                                <p>经纪人奖励</p>
                                <div>
                                    <el-form-item label="奖励来源：" :rules="rules.awardSource" :prop="`formulaPackage.` + index + `.broAward.awardSource`">
                                        <el-select v-model="x.broAward.awardSource">
                                            <el-option v-for="item in awardSources" :label="item.label" :value="item.value" :key="item.label"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </div>
                                <div>
                                    <el-form-item label="奖励方式：" :rules="rules.awardType" :prop="`formulaPackage.` + index + `.broAward.awardType`">
                                        <el-select v-model="x.broAward.awardType">
                                            <el-option v-for="item in awardTypes" :label="item.label" :value="item.value" :key="item.label"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </div>
                                <hr/>

                                <div>
                                    <el-form-item :label="x.broAward.awardSource==2?'好生活总收入：':'经纪人奖励合计：'" :prop="`formulaPackage.` + index + `.broAward.goodLifePackageAmount`"
                                                  :rules="rules.packageAmount">
                                        <el-input v-model.trim="x.broAward.goodLifePackageAmount" style="width: 120px;"></el-input>
                                        元/套<span style="padding-left: 20px; color: #888;">注：{{x.broAward.awardSource==2?'好生活总收入：':'经纪人奖励合计：'}}=经纪人奖励+好生活分佣+开发商分佣</span>
                                    </el-form-item>
                                </div>
                                <!--业绩确认节点-->
                                <div>
                                    <el-form-item label="业绩确认节点：" :rules="rules.goodLifeNode" :prop="`formulaPackage.` + index + `.broAward.goodLifeNode`" class="commonclass">
                                        <el-radio-group v-model="x.broAward.goodLifeNode" @change="broChange(x)">
                                            <el-radio :label="item.value" :key="item.value" v-for="item in x.customeNode">{{item.label}}</el-radio>
                                        </el-radio-group>
                                    </el-form-item>
                                </div>
                                <hr>

                                <div>
                                    <el-form-item label="经纪人奖励：" :prop="`formulaPackage.` + index + `.broAward.packageAmount`"
                                                  :rules="rules.packageAmount" >
                                        <el-input v-model.trim="x.broAward.packageAmount" style="width: 120px;"></el-input>
                                        元/套
                                    </el-form-item>
                                </div>
                                <!--节点-->
                                <div class="clear clearthat commonclass" v-for="(item,index1) in x.broAward.brokerageNodes" :key="index1">
                                    <el-form-item :label="'节点'+(index1+1)+'：'" >
                                        {{item.nodeName}}
                                        <el-input v-model.trim="item.brokeNodeAmount" style="width: 120px;"></el-input> 元/套
                                    </el-form-item>
                                </div>
                                <hr>

                                <div>
                                    <el-form-item label="好生活分佣：" :prop="`formulaPackage.` + index + `.broAward.goodLifeGrantPackageAmount`"
                                                  :rules="rules.packageAmount">
                                        <el-input v-model.trim="x.broAward.goodLifeGrantPackageAmount" style="width: 120px;"></el-input>
                                        元/套
                                    </el-form-item>
                                </div>
                                <div>
                                    <el-form-item label="开发商分佣：" :prop="`formulaPackage.` + index + `.broAward.openBusinessGrantPackageAmount`"
                                                  :rules="rules.packageAmount">
                                        <el-input v-model.trim="x.broAward.openBusinessGrantPackageAmount" style="width: 120px;"></el-input>
                                        元/套
                                    </el-form-item>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="content">
                                <p class="pad red">
                                    预计总佣金=
                                    <span v-if="form.brokerageType == 1 || form.brokerageType == 3">{{hehe(form.brokerageType,form.front.formula,x.front)}}</span>
                                    <span v-if="form.brokerageType == 3"> + </span>
                                    <span v-if="form.brokerageType == 2 || form.brokerageType == 3">{{hehe(form.brokerageType,form.end.formula,x.end)}}</span>
                                    <span v-if="roletype==3&&form.isAward==1"> + </span>
                                    <span v-if="roletype==3&&form.isAward==1">{{x.broAward.goodLifePackageAmount}} 元/套</span>
                                </p>
                                <div>
                                    <el-form-item label="套餐名称："
                                                  :rules="rules.packageName"
                                                  :prop="`formulaPackage.` + index + `.packageName`">

                                        <el-input v-model="x.packageName" style="width: 620px;" :maxlength="50"></el-input>
                                        <span class="grey pad">请录入能够吸引经纪人的套餐名称，如7%垫佣</span>
                                    </el-form-item>
                                </div>
                                <div>
                                    <el-form-item label="套餐说明："
                                                  :rules="rules.packageExplain"
                                                  :prop="`formulaPackage.` + index + `.packageExplain`">

                                        <el-input v-model="x.packageExplain" style="width: 620px;" :maxlength="200" type="textarea" :rows="4"></el-input>
                                        <span class="grey pad">请录入能够吸引经纪人的套餐说明，如以月为单位跳点结佣<br>
                                            还可以再输入{{200-x.packageExplain.length}}
                                        </span>
                                    </el-form-item>
                                </div>
                            </td>
                        </tr>
                    </tbody>

                </table>
                <div class="tips" v-show="form.roleList.indexOf(0) > -1">
                    <p>说明：关于佣金税费，网络推客按照劳务所得税扣除税点；</p>
                </div>
                <el-button type="primary" @click="addTc">增加</el-button>
                <el-form-item>
                    <el-button type="primary" @click="prev">上一步</el-button>
                    <el-button type="primary" @click="finish(1)" :loading="loadingBtn == 1">完成</el-button>
                </el-form-item>
            </div>
        </el-form>
        <el-dialog title="流程审批" :visible.sync="dialogVisible"  :append-to-body="true" width="50%" :close-on-click-modal="false" @close="closeModle">
            <!-- v2.10 -->
            <p class="commonprogress commonP">流程审批名称</p>
            <el-input v-model="form.manualProcessName" placeholder="名称" maxlength="30"></el-input>
            <p class="commonprogress commonP">超标原因说明</p>
            <el-input
                    type="textarea"
                    placeholder="超标原因说明"
                    v-model.trim="form.exceedReason"
                    maxlength="300"
                    show-word-limit
            >
            </el-input>
            <p class="commonP" style="margin-top: 25px;">上传附件</p>
            <el-button @click="uploadHandle">+</el-button>
            <input type="file" ref="inputfile" @change="fileChangeHandle" style="display: none;">
            <el-table :data="form.accessories" border stripe style="margin-top: 15px;border:none;">
                <el-table-column  prop="fileTextName" align="center"  label="文件名"></el-table-column>
                <el-table-column  prop="fileSize" align="center"  label="大小"></el-table-column>
                <el-table-column  prop="createPerson" align="center"  label="创建人"></el-table-column>
                <el-table-column  prop="uploadTime" align="center"  label="上传时间"></el-table-column>
                <el-table-column  label="操作" align="center" >
                    <template slot-scope="scope">
                        <el-button size="small" type="text" @click="delaccessory(scope.row)">删除文件</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <el-button type="primary" style="margin-top:25px;" @click="submitcheck" :loading="checkBtnLoading">提交审核</el-button>
        </el-dialog>
        <cesuanDialog ref="cesuanDialog" :checked="checked" :cesuanCopy="cesuanCopy"></cesuanDialog>
    </div>
</template>

<script>
import api from "@/api/apiPath"
import Util from "@/common/utils"
import * as qiniu from 'qiniu-js'
import cesuanDialog from './cesuanDialog'

export default {
    name:"operateBrokerageRule",
    created() {
        this.pageType = this.$route.query.type
        this.loadCity()
    },
    mounted() {},
    components: {cesuanDialog},
    data() {
        return {
            checkBtnLoading:false,
            dialogVisible:false,
            active: 1,
            alpha: '一二三四五六七八九十',
            // =================================================第一步
            roletype: 3,
            // =================================================第二步
            citys: [],
            curCity: '',
            devs: [],
            curDev: '',
            checked: [],// 已选择的楼盘
            pickerOption:{
                disabledDate(time) {
                    return time.getTime() < Date.now()- 8.64e7;
                }
            },
            nodeRulesList: [],

            // =================================================第三步

            // =================================================第四步
            tempAwardSources:[
                {label: '前佣-经纪人分佣', value: 5},
                {label: '后佣-经纪人分佣', value: 6},
                {label: '开发商-返还款', value: 1},
                {label: '开发商-回款', value: 2},
            ],
            awardSources:[],
            options: [
                {label: '百分比', value: 1},
                {label: '固定金额', value: 2}
            ],
            awardTypes:[
                {label: '购物卡', value: 1},
                {label: '现金', value: 2}
            ],
            loadingBtn:0,
            form: {
                manualProcessName:'',//超标名称
                exceedReason:"",//超标原因
                accessories:[],//超标附件
                estateIdList: [],
                roleList: [3],// 角色类型
                brokerageType: 1, // 佣金类型
                packageStarTime: '', // 套餐有效期
                packageEndTime: '',
                nodeRuleId: '',// 节点规则
                mattressList:[],//垫付角色
                front: {
                    brokerageFormulaType: 1,
                    formula: 1,
                    HouseMoneyTaxPoint: '5',
                    RenovationTaxPoint: '11'
                },
                end: {
                    brokerageFormulaType: 2,
                    formula: 1,
                    HouseMoneyTaxPoint: '5',
                    RenovationTaxPoint: '11'
                },
                bro:{//经纪人奖励公式
                    brokerageFormulaType: 3,
                    formula: 1,
                },
                formulaPackage: [
                    {
                        packageName: '',
                        packageExplain: '',
                        customeNode:[],//结佣节点数组
                        front: {
                            //brokerageFormulaType: 3,
                            //套餐类型 1.前佣 2.后佣
                            packageBrokerageType: 1,

                            packageAmount: '',//经纪人套餐金额(公式一)

                            goodLifePackageAmount:"",//好生活总收入套餐金额（公式一）
                            goodLifeProportion:"",//好生活总收入佣金比例
                            goodLifeGrantPackageAmount:"",//好生活分佣套餐金额（公式一）
                            goodLifeGrantProportion:"",//好生活分佣佣金比例
                            openBusinessGrantPackageAmount:"",//开发商分佣金额（公式一）
                            openBusinessGrantProportion:"",//开发商分佣佣金比例
                            goodLifeAmount:"",//含税成交价+金额公式里面好生活总收入的金额
                            goodLifePercentage:100,//好生活总收入结佣百分比
                            goodLifeGrantAmount:"",//含税成交价+金额公式里面好生活分佣结佣金额
                            goodLifeGrantPercentage:100,//好生活分佣结佣百分比
                            openBusinessGrantAmount:"",//含税成交价+金额公式里开发商分佣金额
                            openBusinessGrantPercentage:100,//开发商分佣百分比
                            // packageStrawSign:1,//草签结佣类型
                            // strawSignAmount:"0",//草签结佣金额或百分比
                            //含税
                            afterTaxAmount: '',
                            brokerageProportion: '',//经纪人佣金比例
                            //不含税
                            preTaxAmount: '',
                            brokerageAmount: '',//含税成交价+金额公式里面经纪人的金额
                            brokeragePercentage:100,//经纪人结佣百分比

                            //认购结佣
                            // packageSubscription: 2,
                            //认购结佣价
                            // subscriptionAmount: '0',
                            //上限
                            packageUpperLimit: 2,
                            //上限金额
                            upperLimitAmount: '',
                            //签约结佣
                            // packageContract: 2,
                            //签约结佣金额
                            // contractAmount: '0',
                            goodLifeNode:1,//1代表前佣，2代表后佣
                            goodLifeNodeName:"",
                            brokerageNodes:[]
                        },
                        end: {
                            //brokerageFormulaType: 2,
                            packageBrokerageType: 2,

                            packageAmount: '',//经纪人套餐金额(公式一)

                            goodLifePackageAmount:"",//好生活总收入套餐金额（公式一）
                            goodLifeProportion:"",//好生活总收入佣金比例
                            goodLifeGrantPackageAmount:"",//好生活分佣套餐金额（公式一）
                            goodLifeGrantProportion:"",//好生活分佣佣金比例
                            openBusinessGrantPackageAmount:"",//开发商分佣金额（公式一）
                            openBusinessGrantProportion:"",//开发商分佣佣金比例
                            goodLifeAmount:"",//含税成交价+金额公式里面好生活总收入的金额
                            goodLifePercentage:100,//好生活总收入结佣百分比
                            goodLifeGrantAmount:"",//含税成交价+金额公式里面好生活分佣结佣金额
                            goodLifeGrantPercentage:100,//好生活分佣结佣百分比
                            openBusinessGrantAmount:"",//含税成交价+金额公式里开发商分佣金额
                            openBusinessGrantPercentage:100,//开发商分佣百分比
                            // packageStrawSign:1,//草签结佣类型
                            // strawSignAmount:"0",//草签结佣金额或百分比
                            brokerageProportion: '',//经纪人佣金比例
                            //不含税
                            preTaxAmount: '',
                            brokerageAmount: '',//含税成交价+金额公式里面经纪人的金额
                            brokeragePercentage:100,//经纪人结佣百分比

                            //认购结佣
                            // packageSubscription: 1,
                            //认购结佣价
                            // subscriptionAmount: '0',
                            //上限
                            packageUpperLimit: 2,
                            //上限金额
                            upperLimitAmount: '',
                            //签约结佣
                            // packageContract: 1,
                            //签约结佣金额
                            // contractAmount: '0',
                            goodLifeNode:2,//1代表前佣，2代表后佣
                            goodLifeNodeName:"",
                            brokerageNodes:[]
                        },
                        broAward:{//经纪人奖励
                            packageBrokerageType: 3,
                            awardSource:"",//奖励来源
                            awardType:"",//奖励方式
                            packageAmount: "",//经纪人套餐金额
                            goodLifePackageAmount: "",//好生活总收入套餐金额
                            goodLifeGrantPackageAmount: "",//好生活分佣
                            openBusinessGrantPackageAmount:'',//开发商分佣
                            goodLifeNode: "",
                            goodLifeNodeName: "",
                            brokerageNodes:[]
                        }
                    }
                ]
            },
            rules: {
                awardSource:{
                    required: true,message: '请选择奖励来源',trigger: 'change'
                },
                awardType:{
                    required: true,message: '请选择奖励方式',trigger: 'change'
                },
                //(单个金额)
                packageAmount: {
                    validator: (rule, value, callback) => {
                        let reg = /^(\-|\+)?\d+(\.\d*)?$/;
                        if (!reg.test(value)) {
                            return callback(new Error('最多保留两位小数'));
                        }
                        callback();
                    }
                },
                //佣金比例
                brokerageProportion: {
                    required: true,
                    validator: (rule, value, callback) => {
                        if (!value) {
                            return callback(new Error('请填写佣金比例'));
                        }

                        let reg = /^(\-|\+)?\d+(\.\d*)?$/;
                        if (!reg.test(value)) {
                            return callback(new Error('最多保留两位小数'));
                        }
                        callback();
                    }
                },
                //金额
                brokerageAmount: {
                    required: true,
                    validator: (rule, value, callback) => {
                        if (!value) {
                            return callback(new Error('请填写金额'));
                        }
                        let reg = /^(-)?\d+(\.\d*)?$/;
                        if (!reg.test(value)) {
                            return callback(new Error('金额最多保留两位小数'));
                        }
                        callback();
                    }
                },

                //上限
                upperLimitAmount: {
                    required: true,
                    validator: (rule, value, callback) => {
                        if (!value) {
                            return callback(new Error('请填写上限认购金额'));
                        }
                        let reg = /^\d+$/;
                        if (!reg.test(value)) {
                            return callback(new Error('上限认购金额为整数'));
                        }
                        callback();
                    }
                },

                //请填写套餐名称
                packageName: {
                    required: true, message: '请输入套餐名称'
                },
                //请填写套餐名称
                packageExplain: {
                    required: true, message: '请输入套餐说明'
                },
                //请选择佣金节点
                goodLifeNodeName:{ required: true, message: '请选择佣金节点'},
                //金额百分比
                packageAmountPercent:{required: true, message: '请输入金额百分比'}

            },
            cesuanCopy:{},
        }
    },
    methods: {
        // ==============================================================================
        warn(msg) {
            this.$alert(msg, '提示', {
                type: 'error',
                confirmButtonText: '确定',
            });
        },
        prev() {
            this.active--;
        },
        next() {
            if (this.active == 1) {
                let roleId = 0
                if(this.roletype == 3) {
                    roleId = 0
                } else if (this.roletype == 0) {
                    roleId = 1
                } else if (this.roletype == -1) {
                    roleId = 2
                }
                this.loadNodeRules(roleId)
            } else if (this.active == 2) {
                if (!this.checked.length) {
                    this.warn('请选择规则适用的楼盘名称');
                    return;
                }
                let s = this.form.packageStarTime;
                if (!s) {
                    this.warn('请选择开始时间');
                    return;
                }
                if (!this.form.packageEndTime) {
                    this.warn('请选择结束时间');
                    return;
                }
                if (this.form.packageStarTime > this.form.packageEndTime) {
                    this.warn('结束时间不能早于开始时间');
                    return;
                }
                if(this.form.formulaPackage.length>1){
                    this.form.formulaPackage=this.form.formulaPackage.slice(0,1)
                }
                if(!this.form.nodeRuleId) {
                    this.warn('请选择节点规则');
                    return;
                }
                if(this.definedNode){
                    // 职业经纪人
                    if(this.form.roleList[0]==3 || this.form.roleList[0]==0){
                        let data=this.definedNode;
                        this.form.formulaPackage[0].customeNode=[]
                        this.form.formulaPackage[0].front.brokerageNodes=[];
                        this.form.formulaPackage[0].end.brokerageNodes=[];
                        let tempNodes=[];
                        let tempNames=[];
                        for(let i=0;i<data.developerNodes.length;i++){
                            this.form.formulaPackage[0].customeNode.push({"value":data.developerNodes[i][0].nodeId,"label":data.developerNodes[i][0].nodeName});
                        }
                        for(let j=0;j<data.brokerageNodes.length;j++){
                            let tempobj=data.brokerageNodes[j];
                            tempNodes=[];
                            tempNames=[];
                            if(tempobj.length>1){
                                for(let m=0;m<tempobj.length;m++){
                                    tempNodes.push(tempobj[m].nodeId);
                                    tempNames.push(tempobj[m].nodeName);
                                    console.log(tempNodes)
                                    console.log(tempNames.join(","))
                                }
                                if(this.form.brokerageType==1){
                                    this.form.formulaPackage[0].front.brokerageNodes.push({
                                        nodeType:2,
                                        combinationNode:tempNodes,
                                        nodeName:tempNames.join(","),
                                        brokeNodeType:1,
                                        brokeNodeAmount:"0",
                                        followType:"CUSTOM",
                                        upperLimitAmount:""
                                    })
                                }else if(this.form.brokerageType==2){
                                    this.form.formulaPackage[0].end.brokerageNodes.push({
                                        nodeType:2,
                                        combinationNode:tempNodes,
                                        nodeName:tempNames.join(","),
                                        brokeNodeType:1,
                                        brokeNodeAmount:"0",
                                        followType:"CUSTOM",
                                        upperLimitAmount:""
                                    })
                                }else{
                                    this.form.formulaPackage[0].front.brokerageNodes.push({
                                        nodeType:2,
                                        combinationNode:tempNodes,
                                        nodeName:tempNames.join(","),
                                        brokeNodeType:1,
                                        brokeNodeAmount:"0",
                                        followType:"CUSTOM",
                                        upperLimitAmount:""
                                    });
                                    this.form.formulaPackage[0].end.brokerageNodes.push({
                                        nodeType:2,
                                        combinationNode:tempNodes,
                                        nodeName:tempNames.join(","),
                                        brokeNodeType:1,
                                        brokeNodeAmount:"0",
                                        followType:"CUSTOM",
                                        upperLimitAmount:""
                                    })
                                }
                            }else{
                                if(this.form.brokerageType==1){
                                    if(tempobj[0].nodeName !="回款"){
                                        this.form.formulaPackage[0].front.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:tempobj[0].nodeType,
                                            upperLimitAmount:""
                                        });
                                    }

                                }else if(this.form.brokerageType==2){
                                    if(tempobj[0].nodeName=="回款"){
                                        this.form.formulaPackage[0].end.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:"RECEPAYM",
                                            upperLimitAmount:""
                                        });
                                    }else{
                                        this.form.formulaPackage[0].end.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:tempobj[0].nodeType,
                                            upperLimitAmount:""
                                        });
                                    }

                                }else{
                                    if(tempobj[0].nodeName !="回款"){
                                        this.form.formulaPackage[0].front.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:tempobj[0].nodeType,
                                            upperLimitAmount:""
                                        });
                                    }
                                    if(tempobj[0].nodeName=="回款"){
                                        this.form.formulaPackage[0].end.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:"RECEPAYM",
                                            upperLimitAmount:""
                                        });
                                    }else{
                                        this.form.formulaPackage[0].end.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:tempobj[0].nodeType,
                                            upperLimitAmount:""
                                        });
                                    }
                                }
                            }

                        }
                    } else if(this.form.roleList[0]==-1){
                        let data=this.definedNode;
                        this.form.formulaPackage[0].customeNode=[]
                        this.form.formulaPackage[0].front.brokerageNodes=[];
                        this.form.formulaPackage[0].end.brokerageNodes=[];
                        let tempNodes=[];
                        let tempNames=[];
                        for(let i=0;i<data.developerNodes.length;i++){
                            this.form.formulaPackage[0].customeNode.push({"value":data.developerNodes[i][0].nodeId,"label":data.developerNodes[i][0].nodeName});
                        }
                        for(let j=0;j<data.brokerageNodes.length;j++){
                            let tempobj=data.brokerageNodes[j];
                            tempNodes=[];
                            tempNames=[];
                            if(tempobj.length>1){
                                for(let m=0;m<tempobj.length;m++){
                                    tempNodes.push(tempobj[m].nodeId);
                                    tempNames.push(tempobj[m].nodeName);
                                    console.log(tempNodes)
                                    console.log(tempNames.join(","))
                                }
                                if(this.form.brokerageType==1){
                                    this.form.formulaPackage[0].front.brokerageNodes.push({
                                        nodeType:2,
                                        combinationNode:tempNodes,
                                        nodeName:tempNames.join(","),
                                        brokeNodeType:1,
                                        brokeNodeAmount:"0",
                                        followType:"CUSTOM",
                                        upperLimitAmount:""
                                    })
                                }else if(this.form.brokerageType==2){
                                    this.form.formulaPackage[0].end.brokerageNodes.push({
                                        nodeType:2,
                                        combinationNode:tempNodes,
                                        nodeName:tempNames.join(","),
                                        brokeNodeType:1,
                                        brokeNodeAmount:"0",
                                        followType:"CUSTOM",
                                        upperLimitAmount:""
                                    })
                                }else{
                                    this.form.formulaPackage[0].front.brokerageNodes.push({
                                        nodeType:2,
                                        combinationNode:tempNodes,
                                        nodeName:tempNames.join(","),
                                        brokeNodeType:1,
                                        brokeNodeAmount:"0",
                                        followType:"CUSTOM",
                                        upperLimitAmount:""
                                    });
                                    this.form.formulaPackage[0].end.brokerageNodes.push({
                                        nodeType:2,
                                        combinationNode:tempNodes,
                                        nodeName:tempNames.join(","),
                                        brokeNodeType:1,
                                        brokeNodeAmount:"0",
                                        followType:"CUSTOM",
                                        upperLimitAmount:""
                                    })
                                }
                            }else{
                                if(this.form.brokerageType==1){
                                    if(tempobj[0].nodeName !="回款"){
                                        this.form.formulaPackage[0].front.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:tempobj[0].nodeType,
                                            upperLimitAmount:""
                                        });
                                    }

                                }else if(this.form.brokerageType==2){
                                    if(tempobj[0].nodeName=="回款"){
                                        this.form.formulaPackage[0].end.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:"RECEPAYM",
                                            upperLimitAmount:""
                                        });
                                    }else{
                                        this.form.formulaPackage[0].end.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:tempobj[0].nodeType,
                                            upperLimitAmount:""
                                        });
                                    }

                                }else{
                                    if(tempobj[0].nodeName !="回款"){
                                        this.form.formulaPackage[0].front.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:tempobj[0].nodeType,
                                            upperLimitAmount:""
                                        });
                                    }
                                    if(tempobj[0].nodeName=="回款"){
                                        this.form.formulaPackage[0].end.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:"RECEPAYM",
                                            upperLimitAmount:""
                                        });
                                    }else{
                                        this.form.formulaPackage[0].end.brokerageNodes.push({
                                            nodeType:1,
                                            brokerageNode:tempobj[0].nodeId,
                                            nodeName:tempobj[0].nodeName,
                                            brokeNodeType:1,
                                            brokeNodeAmount:"0",
                                            followType:tempobj[0].nodeType,
                                            upperLimitAmount:""
                                        });
                                    }
                                }
                            }

                        }
                    }
                }
                for(let i=0,len=this.form.formulaPackage.length;i<len;i++){
                    this.form.formulaPackage[i].broAward.awardSource="";
                }

                if(this.form.brokerageType ==1){// 前佣
                    let temp = []
                    temp.push(this.tempAwardSources[0])
                    temp.push(this.tempAwardSources[2])
                    this.awardSources = temp
                } else if (this.form.brokerageType ==2){
                    let temp2 = [...this.tempAwardSources]
                    temp2.shift()
                    this.awardSources = temp2
                } else {
                    this.awardSources = this.tempAwardSources
                }

            } else if (this.active == 3) {
                let reg = /^\d+(\.\d*)?$/;
                let {
                    brokerageType,
                    front: {formula: f, HouseMoneyTaxPoint: a, RenovationTaxPoint: b},
                    end: {formula: e, HouseMoneyTaxPoint: c, RenovationTaxPoint: d},
                } = this.form;
                //前佣并且选不含税
                if (brokerageType == 1 && (f == 4 || f == 5)) {
                    if (!reg.test(a) || !reg.test(b)) {
                        this.warn('前佣房款税点和装修款税点错误');
                        return;
                    }
                }
                //后佣并且不含税
                if (brokerageType == 2 && (e == 4 || e == 5)) {
                    if (!reg.test(c) || !reg.test(d)) {
                        this.warn('后佣房款税点和装修款税点错误');
                        return;
                    }
                }

                if (brokerageType == 3) {
                    if ((f == 4 || f == 5) && (!reg.test(a) || !reg.test(b))) {
                        this.warn('前佣房款税点和装修款税点错误');
                        return;
                    }
                    if ((e == 4 || e == 5) && (!reg.test(c) || !reg.test(d))) {
                        this.warn('后佣房款税点和装修款税点错误');
                        return;
                    }
                }
                if(this.roletype==3 && this.form.isAward==1){
                    this.form.formulaPackage[0].broAward.brokerageNodes=this.transerNames;
                    this.form.bro.awardNodes=this.transerNames;
                }
                this.axios.post(api.UPLOADTOKEN, {}).then(res => {
                    this.token = res.data.data.imgToken
                    this.qiniuUrl = res.data.data.qiniuUrl
                })
            }
            this.active++;
        },
        loadCity() {
            this.axios.post(api.CITYLIST).then(res => {
                this.citys = res.data.data.cityList
            });
        },
        uploadHandle () {
            const node = this.$refs.inputfile
            node.click()
        },
        fileChangeHandle () {
            const file = this.$refs.inputfile.files[0]
            // 判断文件类型
            const upType = ['jpg', 'png','jpeg','pdf','PDF']
            const fileName = file.name
            const postfix = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length)
            if (upType.indexOf(postfix) === -1) {
                alert('只支持png jpg jpeg格式的图片或PDF')
                return false
            }
            this.uploadQiniu(file)
        },
        // 用七牛上传
        uploadQiniu (file) {
            const fileName = file.name
            const postfix = fileName.substring(fileName.lastIndexOf('.'), fileName.length)
            const name = Util.getTimeString2(new Date().getTime())
            const token = this.token
            var putExtra = {
                fname: fileName,
                params: {},
                mimeType: null
            }
            var config = {
                useCdnDomain: true
            }
            var observable = qiniu.upload(file, name + postfix, token, putExtra, config)
            const vueThis = this
            this.percentShow = true
            this.percentage = 10
            observable.subscribe(function (res) {
                console.log('图片上传进度：', res)
                vueThis.percentage = res.total.percent
            }, function (error) {
                console.error('图片上传失败：', error)
            }, function (res) {
                vueThis.imgUrl = vueThis.qiniuUrl + res.key
                var fileItem={};
                fileItem.createPerson=localStorage.getItem('cmsUser')?JSON.parse(localStorage.getItem('cmsUser')).name:'';
                fileItem.fileSize=((file.size/1024)>100)?((file.size/1024/1024).toFixed(2)+"MB"):((file.size/1024).toFixed(2)+"Kb");
                fileItem.uploadTime=vueThis.getTimeString(new Date().getTime());
                fileItem.fileTextName=fileName;
                fileItem.fileTextAddress=vueThis.imgUrl;
                vueThis.form.accessories.push(fileItem);
            })
        },
        getTimeString (timestamp) {
            if (timestamp) {
                const time = new Date(timestamp)
                let dateStr = ''
                const year = time.getFullYear()
                const month = String(time.getMonth() + 1).length === 1 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1)
                const day = String(time.getDate()).length === 1 ? '0' + time.getDate() : time.getDate()
                dateStr = year + '-' + month + '-' + day
                let timeStr = ''
                const hours = time.getHours()
                const hh = String(hours).length === 1 ? '0' + hours : hours
                const minutes = time.getMinutes()
                const mm = String(minutes).length === 1 ? '0' + minutes : minutes
                const seconds = time.getSeconds()
                const ss = String(seconds).length === 1 ? '0' + seconds : seconds
                timeStr = `${hh}:${mm}:${ss}`
                // timeStr = `${hh}:${mm}`
                return dateStr + ' ' + timeStr
                // return dateStr
            } else {
                return ''
            }
        },

        delaccessory(data){
            this.$confirm('此操作将删除该文件，是否继续？',"提示",{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(()=>{
                this.$alert("操作成功","提示",{
                    confirmButtonText: '确定',
                    type: 'warning',
                    callback:action=>{
                        for(var i=0;i<this.form.accessories.length;i++){
                            if(data.fileTextName==this.form.accessories[i].fileTextName){
                                this.form.accessories.splice(i,1);
                            }
                        }
                    }
                })
            }).catch(()=>{});
        },
        showLoading(){
            loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
        },
        closeModle(){
            console.log("sss");
        },
        submitcheck(){
            if (this.form.manualProcessName =="") {
                this.warn("请输入流程审批名称");
                return;
            }
            if(this.form.exceedReason==""){
                this.warn("请输入超标原因");
                return;
            }
            this.checkBtnLoading=true;
            this.finish(2);
        },
        // =================================================第一步
        // 角色类型改变
        roleTypeChange(val) {
            this.form.roleList=[];
            this.form.roleList.push(val)
        },
        // =================================================第二步
        loadDev() {
            this.curDev = '';
            this.axios.post(api.ruleGetDevList,{cityId: this.curCity,devStatus:1}).then(res => {
                this.devs = res.data.data;
            });
        },

        addDev() {
            if(this.curDev){
                let {city} = this.citys.find(it => it.cityId == this.curCity);
                let {devName: name, devId: id} = this.devs.find(it => it.devId == this.curDev);
                if (!this.checked.find(it => it.id == id)) {
                    this.checked.push({name: city + '-' + name, id});
                    this.$message.success('添加成功')
                } else {
                    this.warn('该楼盘已绑定，请勿重复绑定');
                }
            } else {
                if (!this.curCity) {
                    this.warn('请选择城市');
                    return;
                }
                let {city} = this.citys.find(it => it.cityId == this.curCity);
                this.devs.forEach(item=>{
                    if (!this.checked.find(it => it.id == item.devId)) {
                        this.checked.push({name: city + '-' + item.devName, id:item.devId});
                    }

                })
                if(this.checked.length>0){
                    this.$message.success('添加成功')
                }
            }


        },
        deleteDev(index) {
            this.checked.splice(index, 1);
            this.$message.success('删除成功')
        },
        // 节点规则列表
        loadNodeRules(id){
            this.form.nodeRuleId="";
            this.axios.post(api.nodeRuleList, {pageNum: -1, pageSize: 999, payForRole: id}).then(res => {
                this.nodeRulesList = res.data.data.responseDate
            })
        },
        // 获取节点规则详情
        getNodeRuleDetail(){
            this.axios.post(api.findNodeRuleNameById,{id:this.form.nodeRuleId}).then(res => {
                const temp = res.data.data
                console.log(temp)
                this.definedNode = temp
                this.form.isAward = temp.isAward
                if(temp.isAward ==1 && this.roletype == 3){
                    this.transerNames = []
                    temp.awardsNodes.forEach(item => {
                        this.transerNames.push({
                            brokerageNode: item[0].nodeId,
                            nodeName: item[0].nodeName,
                            brokeNodeAmount:"",
                            followType: item[0].nodeType
                        })
                    })
                }
            })
        },
        // =================================================第三步
        toggleFormula(val, f) {
            this.form.formulaPackage.forEach(it => {
                if(f=="front"){
                    if (val !== 1) {
                        it[f].packageSubscription = 1;
                        it[f].packageContract = 1;
                    } else {
                        it[f].packageSubscription = 2;
                        it[f].packageContract = 2;
                    }
                }
                if(f=="end"){
                    if (val !== 1) {
                        it[f].packageContract = 1;
                    } else {
                        it[f].packageContract = 2;
                    }
                }
            });
        },
        // =================================================第四步
        frontChange(val){
            let obj = {};
            obj = val.customeNode.find((item)=>{
                return item.value === val.front.goodLifeNode;
            });
            val.front.goodLifeNodeName=obj.label;
        },
        endChange(val){
            let obj = {};
            obj = val.customeNode.find((item)=>{
                return item.value === val.end.goodLifeNode;
            });
            val.end.goodLifeNodeName=obj.label;
        },
        broChange(val){
            let obj = {};
            obj = val.customeNode.find((item)=>{
                return item.value === val.broAward.goodLifeNode;
            });
            val.broAward.goodLifeNodeName=obj.label;
        },
        frontChange(val){
            let obj = {};
            obj = val.customeNode.find((item)=>{
                return item.value === val.front.goodLifeNode;
            });
            val.front.goodLifeNodeName=obj.label;
        },
        addTc() {
            let {
                front: {packageBrokerageType},
                end: {packageBrokerageType: ptype}
            } = this.form.formulaPackage[0];

            var temppps={
                packageName: '',
                packageExplain: '',
                mattressList:this.form.mattressList,//垫付角色（0 职业经济人，1网络推客）
                customeNode:this.form.formulaPackage[0].customeNode,//结佣节点数组
                front: {
                    //brokerageFormulaType: brokerageFormulaType,
                    packageBrokerageType: packageBrokerageType,
                    packageAmount: '',//经纪人套餐金额(公式一)
                    /*stl*/
                    goodLifePackageAmount:"",//好生活总收入套餐金额（公式一）
                    goodLifeProportion:"",//好生活总收入佣金比例
                    goodLifeGrantPackageAmount:"",//好生活分佣套餐金额（公式一）
                    goodLifeGrantProportion:"",//好生活分佣佣金比例
                    openBusinessGrantPackageAmount:"",//开发商分佣金额（公式一）
                    openBusinessGrantProportion:"",//开发商分佣佣金比例
                    goodLifeAmount:"",//含税成交价+金额公式里面好生活总收入的金额
                    goodLifePercentage:100,//好生活总收入结佣百分比
                    goodLifeGrantAmount:"",//含税成交价+金额公式里面好生活分佣结佣金额
                    goodLifeGrantPercentage:100,//好生活分佣结佣百分比
                    openBusinessGrantAmount:"",//含税成交价+金额公式里开发商分佣金额
                    openBusinessGrantPercentage:100,//开发商分佣百分比
                    // packageStrawSign:1,//草签结佣类型
                    // strawSignAmount:"0",//草签结佣金额或百分比
                    //含税
                    afterTaxAmount: '',
                    brokerageProportion: '',//经纪人佣金比例
                    //不含税
                    preTaxAmount: '',
                    brokerageAmount: '',//含税成交价+金额公式里面经纪人的金额
                    brokeragePercentage:100,//经纪人结佣百分比
                    //认购结佣
                    // packageSubscription: 2,
                    //认购结佣价
                    // subscriptionAmount: '0',
                    //上限
                    packageUpperLimit: 2,
                    //上限金额
                    upperLimitAmount: '',
                    //签约结佣
                    // packageContract: 2,
                    //签约结佣金额
                    // contractAmount: '0',
                    goodLifeNode:1,//1代表前佣，2代表后佣
                    goodLifeNodeName:"",
                    brokerageNodes:this.form.formulaPackage[0].front.brokerageNodes
                },
                end: {
                    //brokerageFormulaType: btype,
                    packageBrokerageType: ptype,
                    packageAmount: '',//经纪人套餐金额(公式一)
                    /*stl*/
                    goodLifePackageAmount:"",//好生活总收入套餐金额（公式一）
                    goodLifeProportion:"",//好生活总收入佣金比例
                    goodLifeGrantPackageAmount:"",//好生活分佣套餐金额（公式一）
                    goodLifeGrantProportion:"",//好生活分佣佣金比例
                    openBusinessGrantPackageAmount:"",//开发商分佣金额（公式一）
                    openBusinessGrantProportion:"",//开发商分佣佣金比例
                    goodLifeAmount:"",//含税成交价+金额公式里面好生活总收入的金额
                    goodLifePercentage:100,//好生活总收入结佣百分比
                    goodLifeGrantAmount:"",//含税成交价+金额公式里面好生活分佣结佣金额
                    goodLifeGrantPercentage:100,//好生活分佣结佣百分比
                    openBusinessGrantAmount:"",//含税成交价+金额公式里开发商分佣金额
                    openBusinessGrantPercentage:100,//开发商分佣百分比
                    // packageStrawSign:1,//草签结佣类型
                    // strawSignAmount:"0",//草签结佣金额或百分比
                    brokerageProportion: '',//经纪人佣金比例
                    //不含税
                    preTaxAmount: '',
                    brokerageAmount: '',//含税成交价+金额公式里面经纪人的金额
                    brokeragePercentage:100,//经纪人结佣百分比
                    //
                    brokerageAmount: '',
                    //认购结佣
                    // packageSubscription: 2,
                    //认购结佣价
                    // subscriptionAmount: '',
                    //上限
                    packageUpperLimit: 2,
                    //上限金额
                    upperLimitAmount: '',
                    //签约结佣
                    // packageContract: 2,
                    //签约结佣金额
                    // contractAmount: '0',
                    goodLifeNode:2,//1代表前佣，2代表后佣
                    goodLifeNodeName:"",
                    brokerageNodes:this.form.formulaPackage[0].end.brokerageNodes
                },
                broAward:{//经纪人奖励
                    packageBrokerageType: 3,
                    awardSource:"",//奖励来源
                    awardType:"",//奖励方式
                    packageAmount: "",//经纪人套餐金额
                    goodLifePackageAmount: "",//好生活总收入套餐金额
                    goodLifeGrantPackageAmount: "",//好生活分佣
                    openBusinessGrantPackageAmount:'',//开发商分佣
                    goodLifeNode: "",
                    goodLifeNodeName: "",
                    brokerageNodes:this.form.formulaPackage[0].broAward.brokerageNodes
                }
            }
            this.form.formulaPackage.push(JSON.parse(JSON.stringify(temppps)));
            let tempform=this.form.formulaPackage;
            for(let i=1;i<tempform.length;i++){
                console.log(tempform[i]);
                let tempfrontlimit=tempform[tempform.length-1].front.brokerageNodes;
                let tempendlimit=tempform[tempform.length-1].end.brokerageNodes;
                let tempbrokerlimit=tempform[tempform.length-1].broAward.brokerageNodes;
                for(let m=0;m<tempfrontlimit.length;m++){
                    tempfrontlimit[m].brokeNodeAmount=0;
                    if(tempfrontlimit[m].nodeName=="认购"){
                        tempfrontlimit[m].upperLimitAmount=""
                        console.log("前佣上限清空")
                    }
                }
                for(let n=0;n<tempendlimit.length;n++){
                    tempendlimit[n].brokeNodeAmount=0;
                    if(tempendlimit[n].nodeName=="认购"){
                        tempendlimit[n].upperLimitAmount=""
                        console.log("后佣上限清空")
                    }
                }
                for(let n=0;n<tempbrokerlimit.length;n++){
                    tempbrokerlimit[n].brokeNodeAmount=0;
                }
            }
        },
        hehe(type, formula, pack) {
            let mime = {
                '1': `${pack.goodLifePackageAmount}`,
                '2': `含税成交价 * ${pack.goodLifeProportion}%`,
                '3': `含税成交价 * ${pack.goodLifeProportion}%${pack.goodLifeAmount < 0 ? '' : ' + '}${pack.goodLifeAmount}`,
                '4': `不含税成交价 * ${pack.goodLifeProportion}%`,
                '5': `不含税成交价 * ${pack.goodLifeProportion}%${pack.goodLifeAmount < 0 ? '' : ' + '}${pack.goodLifeAmount}`,
                '6': `${pack.goodLifePackageAmount}`,
                '7': `${pack.goodLifePackageAmount}`,
            };
            if(formula==6 || formula==7){
                return mime[formula] + '元/平米'+`*${pack.goodLifePercentage}%`;
            }
            return mime[formula] + '元/套'+`*${pack.goodLifePercentage}%`;
        },
        clear(val,index,i){
            if(val == 2){
                this.form.formulaPackage[index][i].upperLimitAmount = '';
                var tempupperlimt=this.form.formulaPackage[index][i];
                for(var j=0;j<tempupperlimt.brokerageNodes.length;j++){
                    if(tempupperlimt.brokerageNodes[j].nodeName=="认购"){
                        tempupperlimt.brokerageNodes[j].upperLimitAmount=""
                    }
                }
            }

        },
        finish(val) {
            this.$refs['form'].validate(valid => {
                if(!valid){
                    return;
                }
                console.log('form:',this.form)
                for(let i=0,len=this.form.formulaPackage.length;i<len;i++){
                    var tempFrontNodes=this.form.formulaPackage[i].front.brokerageNodes;
                    var tempEndNodes=this.form.formulaPackage[i].end.brokerageNodes;
                    var tempFrontUplimt=this.form.formulaPackage[i].front.packageUpperLimit;
                    var tempEndUplimt=this.form.formulaPackage[i].end.packageUpperLimit;
                    var frontbrokerNode=this.form.formulaPackage[i].front.goodLifeNodeName;
                    var endbrokerNode=this.form.formulaPackage[i].end.goodLifeNodeName;
                    if(this.form.brokerageType==1){//前佣
                        if(frontbrokerNode===""){
                            this.warn(`第${this.alpha[i]}套套餐前佣结佣节点不能为空`);
                            return;
                        }
                    }else if(this.form.brokerageType==2){//后
                        if(endbrokerNode===""){
                            this.warn(`第${this.alpha[i]}套套餐后佣结佣节点不能为空`);
                            return;
                        }
                    }else if(this.form.brokerageType==3){//前+后
                        if(frontbrokerNode===""){
                            this.warn(`第${this.alpha[i]}套套餐前佣结佣节点不能为空`);
                            return;
                        }
                        if(endbrokerNode===""){
                            this.warn(`第${this.alpha[i]}套套餐后佣结佣节点不能为空`);
                            return;
                        }
                    }
                    //校验前佣的渠道分佣的节点不能为空
                    for(var j=0;j<tempFrontNodes.length;j++){
                        if(tempFrontNodes[j].brokeNodeAmount.toString()===""){
                            this.warn(`第${this.alpha[i]}套套餐前佣节点${j+1}不能为空`);
                            return;
                        }
                    }
                    //校验后佣的渠道分佣的节点不能为空
                    for(var j=0;j<tempEndNodes.length;j++){
                        if(tempEndNodes[j].nodeName!="回款"){
                            if(tempEndNodes[j].brokeNodeAmount.toString()===""){
                                this.warn(`第${this.alpha[i]}套套餐后佣节点${j+1}不能为空`);
                                return;
                            }
                        }
                    }
                    let sameFrontArr=[];//判断节点相加是否大于100%或者金额的总数
                    let sameEndArr=[];//判断节点相加是否大于100%或者金额的总数
                    let sumFront=0;
                    let sumEnd=0;
                    let isHuiKuan="";
                    //前
                    for(var j=0;j<tempFrontNodes.length;j++){
                        sameFrontArr.push(tempFrontNodes[j].brokeNodeType);
                    }
                    sameFrontArr=this.dedupe(sameFrontArr);
                    for(var j=0;j<tempFrontNodes.length;j++){
                        if(tempFrontUplimt==1){
                            if(tempFrontNodes[j].nodeName=="认购"){
                                if(tempFrontNodes[j].upperLimitAmount===""){
                                    this.warn(`第${this.alpha[i]}套套餐前佣上限不能为空`);
                                    return;
                                }
                                let reg = /^\d+$/;
                                if (!reg.test(tempFrontNodes[j].upperLimitAmount)) {
                                    this.warn(`第${this.alpha[i]}套套餐前佣上限金额为整数`);
                                    return;
                                }
                            }
                        }
                        sumFront+=parseFloat(tempFrontNodes[j].brokeNodeAmount);

                    }


                    //后
                    for(var j=0;j<tempEndNodes.length;j++){
                        sameEndArr.push(tempEndNodes[j].brokeNodeType);
                    }
                    sameEndArr=this.dedupe(sameEndArr);
                    for(var j=0;j<tempEndNodes.length;j++){
                        if(tempEndUplimt==1){
                            if(tempEndNodes[j].nodeName=="认购"){
                                if(tempEndNodes[j].upperLimitAmount===""){
                                    this.warn(`第${this.alpha[i]}套套餐后佣上限不能为空`);
                                    return;
                                }
                                let reg = /^\d+$/;
                                if (!reg.test(tempEndNodes[j].upperLimitAmount)) {
                                    this.warn(`第${this.alpha[i]}套套餐后佣上限金额为整数`);
                                    return;
                                }
                            }
                        }
                        if(tempEndNodes[j].nodeName=="回款"){
                            isHuiKuan="回款";
                        }
                        sumEnd+=parseFloat(tempEndNodes[j].brokeNodeAmount);
                    }

                    if(this.roletype!=-1){// 自来客不校验求和100
                        if(sameFrontArr.length==1){
                            if(this.form.front.formula==1){//公式1金额
                                if(sameFrontArr[0]==1){
                                    if(sumFront != 100 ){
                                        this.warn(`第${this.alpha[i]}套套餐前佣节点之和必须是100%`);
                                        return;
                                    }
                                }
                                if(sameFrontArr[0]==2){
                                    if((sumFront) != this.form.formulaPackage[i].front.packageAmount*parseFloat(parseFloat(this.form.formulaPackage[i].front.brokeragePercentage)/100)){
                                        this.warn(`第${this.alpha[i]}套套餐前佣节点之和必须为金额设置的值`);
                                        return;
                                    }
                                }
                            }else if(this.form.front.formula==6||this.form.front.formula==7){//公式67面积
                                if(sameFrontArr[0]==1){
                                    if(sumFront != 100 ){
                                        this.warn(`第${this.alpha[i]}套套餐前佣节点之和必须是100%`);
                                        return;
                                    }
                                }
                            }else{// 其他公式
                                if(sameFrontArr[0]==1){
                                    if(sumFront != 100 ){
                                        this.warn(`第${this.alpha[i]}套套餐前佣节点之和必须是100%`);
                                        return;
                                    }
                                }
                            }

                        }
                        if(sameEndArr.length==1){
                            if(this.form.end.formula==1){
                                if(sameEndArr[0]==1){
                                    if(isHuiKuan=='回款'){
                                        if(sumEnd >100){
                                            this.warn(`第${this.alpha[i]}套套餐后佣节点之和不能大于100%`);
                                            return;
                                        }
                                    }else {
                                        if(sumEnd != 100){
                                            this.warn(`第${this.alpha[i]}套套餐后佣节点之和必须为100%`);
                                            return;
                                        }
                                    }

                                }
                                if(sameEndArr[0]==2){
                                    if(sumEnd != this.form.formulaPackage[i].end.packageAmount*parseFloat(this.form.formulaPackage[i].end.brokeragePercentage/100)){
                                        this.warn(`第${this.alpha[i]}套套餐后佣节点之和必须为金额设置的值`);
                                        return;
                                    }
                                }
                            }else if(this.form.end.formula==6||this.form.end.formula==7){
                                if(sameEndArr[0]==1){
                                    if(isHuiKuan=='回款'){
                                        if(sumEnd >100){
                                            this.warn(`第${this.alpha[i]}套套餐后佣节点之和不能大于100%`);
                                            return;
                                        }
                                    }else {
                                        if(sumEnd != 100){
                                            this.warn(`第${this.alpha[i]}套套餐后佣节点之和必须为100%`);
                                            return;
                                        }
                                    }

                                }
                            }else{
                                if(sameEndArr[0]==1){
                                    if(isHuiKuan=='回款'){
                                        if(sumEnd >100){
                                            this.warn(`第${this.alpha[i]}套套餐后佣节点之和不能大于100%`);
                                            return;
                                        }
                                    }else {
                                        if(sumEnd != 100){
                                            this.warn(`第${this.alpha[i]}套套餐后佣节点之和必须为100%`);
                                            return;
                                        }
                                    }

                                }
                            }

                        }
                    }


                    /**
                     * 经纪人奖励的校验
                     */
                    if(this.roletype==3&&this.form.isAward==1){
                        if(this.form.formulaPackage[i].broAward.goodLifeNode===""){
                            this.warn(`请选择第${this.alpha[i]}套套餐经纪人奖励结佣节点`);
                            return;
                        }
                        if(this.form.formulaPackage[i].broAward.awardSource==1){// 奖励来源：开发商返还款
                            if(this.form.brokerageType==1){// 前佣
                                if(this.form.front.formula==1){
                                    if((this.form.formulaPackage[i].front.openBusinessGrantPackageAmount*(this.form.formulaPackage[i].front.openBusinessGrantPercentage/100)-parseFloat(this.form.formulaPackage[i].broAward.goodLifePackageAmount))<0){
                                        this.warn(`第${this.alpha[i]}套套餐前佣开发商分佣需大于经纪人奖励好生活总收入`);
                                        return;
                                    }
                                }
                            }
                            if(this.form.brokerageType==2){// 后佣
                                if(this.form.end.formula==1){
                                    if((this.form.formulaPackage[i].end.openBusinessGrantPackageAmount*(this.form.formulaPackage[i].end.openBusinessGrantPercentage/100)-this.form.formulaPackage[i].broAward.goodLifePackageAmount)<0){
                                        this.warn(`第${this.alpha[i]}套套餐后佣开发商分佣需大于等于经纪人奖励好生活总收入`);
                                        return;
                                    }
                                }
                            }
                            if(this.form.brokerageType==3){// 前+后
                                if(this.form.front.formula==1&&this.form.end.formula==1){
                                    if(
                                        this.form.formulaPackage[i].front.openBusinessGrantPackageAmount *this.form.formulaPackage[i].front.openBusinessGrantPercentage/100
                                        +this.form.formulaPackage[i].end.openBusinessGrantPackageAmount*this.form.formulaPackage[i].end.openBusinessGrantPercentage/100
                                        -this.form.formulaPackage[i].broAward.goodLifePackageAmount
                                        <0
                                    ){
                                        this.warn(`第${this.alpha[i]}套套餐前佣+后佣开发商分佣需大于等于经纪人奖励好生活总收入`);
                                        return;
                                    }
                                }
                            }

                            if(this.form.formulaPackage[i].broAward.goodLifeNode != this.form.formulaPackage[i].broAward.brokerageNodes[0].brokerageNode){
                                this.warn(`第${this.alpha[i]}套套餐奖励来源为开发商-返还款时,奖励的业绩确认节点须与经纪人奖励结佣的第一个节点保持一致!`);
                                return;
                            }
                        }
                        if(this.form.formulaPackage[i].broAward.awardSource==5){//奖励来源：前佣-经纪人分佣
                            if(this.form.formulaPackage[i].broAward.goodLifeNode != this.form.formulaPackage[i].front.goodLifeNode){
                                this.warn(`第${this.alpha[i]}套套餐奖励来源为前佣-经纪人分佣时,奖励的业绩确认节点须与前佣的好生活总收入的业绩确认节点保持一致!`);
                                return;
                            }
                        }
                        if(this.form.formulaPackage[i].broAward.awardSource==6
                            ||this.form.formulaPackage[i].broAward.awardSource==2){//奖励来源：后佣-经纪人分佣，开发商回款
                            if(this.form.formulaPackage[i].broAward.goodLifeNode != this.form.formulaPackage[i].end.goodLifeNode){
                                this.warn(`第${this.alpha[i]}套套餐奖励来源为后佣-经纪人分佣时,奖励的业绩确认节点须与后佣的好生活总收入的业绩确认节点保持一致!`);
                                return;
                            }
                        }
                        let tempBrokerNodes=this.form.formulaPackage[i].broAward.brokerageNodes;
                        let brokerSum=0;
                        for(let t=0;t<tempBrokerNodes.length;t++){
                            if(tempBrokerNodes[t].brokeNodeAmount===""){
                                this.warn(`第${this.alpha[i]}套套餐经纪人奖励节点${t+1}不能为空`);
                                return;
                            }
                            let reg = /^(\-|\+)?\d+(\.\d*)?$/;
                            if(!reg.test(tempBrokerNodes[t].brokeNodeAmount)){
                                this.warn(`第${this.alpha[i]}套套餐经纪人奖励节点${t+1}限数字最多保留两位小数`);
                                return;
                            }
                            brokerSum+=parseFloat(tempBrokerNodes[t].brokeNodeAmount)
                        }
                        if(brokerSum != this.form.formulaPackage[i].broAward.packageAmount){
                            this.warn(`第${this.alpha[i]}套套餐经纪人奖励节点之和需等于经纪人奖励收入`);
                            return;
                        }
                        let tempAwardAmount=this.form.formulaPackage[i].broAward;
                        if(parseFloat(tempAwardAmount.goodLifePackageAmount)
                            != parseFloat(tempAwardAmount.packageAmount)
                            +parseFloat(tempAwardAmount.goodLifeGrantPackageAmount)
                            +parseFloat(tempAwardAmount.openBusinessGrantPackageAmount)
                        ){
                            this.warn(`第${this.alpha[i]}套套餐，经纪人奖励合计≠经纪人奖励+好生活分佣+开发商分佣`);
                            return;
                        }

                    }
                }
                let {front, end, bro, formulaPackage, brokerageType} = this.form;
                let copy = {...this.form};
                delete copy.front;
                delete copy.end;
                delete copy.bro;
                delete copy.formulaPackage;
                //楼盘id
                copy.estateIdList = this.checked.map(it => it.id);
                //公式
                copy.formulaModel = [];
                //套餐
                copy.formulaPackage = [];


                if (brokerageType == 1) {
                    if(this.roletype==3&&this.form.isAward==1){
                        copy.formulaModel.push(front,bro);
                    }else{
                        copy.formulaModel.push(front);
                    }
                } else if (brokerageType == 2) {
                    if(this.roletype==3&&this.form.isAward==1){
                        copy.formulaModel.push(end,bro);
                    }else{
                        copy.formulaModel.push(end);
                    }
                } else {
                    if(this.roletype==3&&this.form.isAward==1){
                        copy.formulaModel.push(front, end,bro);
                    }else{
                        copy.formulaModel.push(front, end);
                    }
                }

                copy.formulaPackage = formulaPackage.map(it => {
                    let clone = {...it};
                    //前佣
                    if (brokerageType == 1) {
                        if(this.roletype==3&&this.form.isAward==1){
                            clone.packageModel = [this.fmt(front.formula, clone.front),this.fmt(bro.formula, clone.broAward)];
                        }else{
                            clone.packageModel = [this.fmt(front.formula, clone.front)];
                        }
                    } else if (brokerageType == 2) {
                        if(this.roletype==3&&this.form.isAward==1){
                            clone.packageModel = [this.fmt(end.formula, clone.end),this.fmt(bro.formula, clone.broAward)];
                        }else{
                            clone.packageModel = [this.fmt(end.formula, clone.end)];
                        }
                    } else {
                        if(this.roletype==3&&this.form.isAward==1){
                            clone.packageModel = [
                                this.fmt(front.formula, clone.front),
                                this.fmt(end.formula, clone.end),
                                this.fmt(bro.formula, clone.broAward)
                            ];
                        }else{
                            clone.packageModel = [
                                this.fmt(front.formula, clone.front),
                                this.fmt(end.formula, clone.end)
                            ];
                        }

                    }
                    delete clone.front;
                    delete clone.end;
                    delete clone.broAward;
                    return clone;
                });

                if(val==3){// 佣金测算
                    this.cesuanCopy = JSON.parse(JSON.stringify(copy))
                    this.$refs.cesuanDialog.showDialog()
                }

                if(val==1){//验证是否符合标准
                    this.loadingBtn=1;
                    this.axios.post(api.checkRule, copy).then(res => {
                        if (res.data.code === 200) {
                            if(res.data.data){
                                this.$alert('佣金套餐设置不符合佣金结算标准,须走流程审批!', '提示', {
                                    confirmButtonText: '确定',
                                    type: 'warning',
                                    callback: action => {
                                        this.loadingBtn=0;
                                        this.dialogVisible=true;
                                        this.checkBtnLoading=false;
                                    }
                                });
                            }else if(res.data.data==null){
                                this.$alert(res.data.msg, '提示', {
                                    confirmButtonText: '确定',
                                    type: 'warning',
                                    callback: action => {
                                        this.loadingBtn=0;
                                        this.dialogVisible=true;
                                        this.checkBtnLoading=false;
                                    }
                                });
                            }else{// 符合标准
                                this.saveParams(copy);
                            }
                        } else {
                            this.$alert(res.msg, '提示', {
                                type: 'error',
                                callback: action => {
                                    this.loadingBtn=0;
                                }
                            });
                        }
                    }).catch(err=>{
                        this.loadingBtn=0;
                    })
                }
                if(val==2){//不用再检测是否符合标准
                    this.saveParams(copy);
                }
            });
        },
        // 数组去重
        dedupe(array){
            return Array.from(new Set(array));
        },
        fmt(type, obj) {
            if (type == 1) {
                delete obj.brokerageProportion;
                delete obj.afterTaxAmount;
                delete obj.preTaxAmount;
            } else if (type == 2) {
                delete obj.packageAmount;
                delete obj.afterTaxAmount;
                delete obj.preTaxAmount;
            } else if (type == 3) {
                delete obj.packageAmount;
                delete obj.preTaxAmount;
            } else if (type == 4) {
                delete obj.packageAmount;
                delete obj.afterTaxAmount;
                delete obj.preTaxAmount;
            } else if (type == 5) {
                delete obj.packageAmount;
                delete obj.afterTaxAmount;
            }
            obj.packageFormula = type;
            return obj;
        },
        AmountBlur(val){
            let reg = /^(\-|\+)?\d+(\.\d*)?$/;
            if (!reg.test(val)) {
                this.warn('限数字且最多保留两位');
                return;
            }
        },
        saveParams(param){
            this.axios.post(api.saveRule, param).then(res => {
                if (res.data.code === 200) {
                    this.$alert('创建成功', '提示', {
                        confirmButtonText: '确定',
                        type: 'success',
                        callback: action => {
                            this.$router.push({path: '/brokerageRuleList'})
                        }
                    });
                } else {
                    this.$alert(res.msg, '提示', {
                        type: 'error',
                        callback: action => {
                            this.loadingBtn=0;// 完成按钮重置
                            this.checkBtnLoading=false; // 提交审核按钮重置
                        }
                    });
                }
            });
        },
        delPackage(i) {
            this.form.formulaPackage.splice(i, 1);
        },

    },
    computed: {}
}
</script>
<style lang="stylus">
    .operateBrokerageRule {
        .my-step{
            position: relative;
            .cesuan{
                position: absolute;
                right: 60px;
                top: 0;
                cursor: pointer;
                .cesuan-img{
                    text-align: center;
                }
            }
        }
        hr {
            margin-top: 20px;
            margin-bottom: 20px;
            border: 0;
            border-top: 1px solid #eee;
        }
        .contact {
            background: #ff4949;
            float: left;
            margin: 0 15px 8px 0;
            position: relative;
            border-radius: 4px;
            color: #fff;
            padding: 8px 25px 8px 10px;
            i.close-icon {
                position: absolute;
                right: 5px;
                top: 1px;
                line-height: 1;
                color: #fff;
                font-style: normal;
                cursor: pointer;
                font-size: 24px;
            }
        }

        .tips {
            color: #777;
            background: #ddd;
            padding: 10px 50px;
            margin: 20px 0;
            font-size: 14px;
            &>div{
                line-height: 30px;
            }
        }
        table{
            width: 100%;
            border-collapse: collapse;
            td {
              border: 1px solid #ccc;
            }
            td.title {
                text-align: center;
            }

            td.content {
                padding-left: 100px;
                padding-top: 10px;
            }
            .pad {
                padding-left: 30px;
            }

            .mar {
                margin-right: 30px;
            }

            .grey {
                color: #ccc;
            }

            .red {
                color: #ff0000;
            }
        }
        .clear {
            display: block;
            overflow: hidden;
        }
        .clear .el-form-item:nth-of-type(2) .el-form-item__label{
            width:50px !important;
        }
        .clear .el-form-item:nth-of-type(2) .el-form-item__label:before{
            content:"" !important;
        }
        .clear .el-form-item:nth-of-type(2) .el-form-item__content{
            margin-left: 50px !important;
        }
        .clearthat .el-form-item:nth-of-type(2) .el-form-item__label{
            width:150px !important;
        }
        .clearthat .el-form-item:nth-of-type(2) .el-form-item__label:before{
            content:"*" !important;
        }
        .clearthat .el-form-item:nth-of-type(2) .el-form-item__content{
            margin-left: 150px !important;
        }
        .clearthis{
            display: block;
            overflow: hidden;
        }
        .commonclass .el-form-item__label:before{
            content: '*';
            color: #f56c6c;
            margin-right: 4px;
        }
        .commonprogress:before{
            content: '*';
            color: #f56c6c;
            margin-right: 4px;
        }

    }
</style>
